package com.andnnl.fileanalysis;

/**
 * Created by chenss on 2021/6/3.
 */
public class AnalysisParam {
    private int maxRow;//最大读取行数
    private int batchSize = 1;//批量模式
    private int delHeadRows = 0;//删除头部行数，空行不算
    private String charset = "";//文件编码
    private String ext = "";//指定文件扩展号
    private String splitRegex = ",|，";//txt文件分割正则
    private int splitLimit = 0;//txt文件分割列数

    //需要重置的参数
    private int headRowCount = 0;//删除头部行数计数

    public static AnalysisParam build() {
        return new AnalysisParam();
    }

    public int getMaxRow() {
        return maxRow;
    }

    /**
     * 最大读取行数
     *
     * @param maxRow
     * @return
     */
    public AnalysisParam setMaxRow(int maxRow) {
        this.maxRow = maxRow;
        return this;
    }

    public int getBatchSize() {
        return batchSize;
    }

    public AnalysisParam setBatchSize(int batchSize) {
        this.batchSize = batchSize;
        return this;
    }

    public int getDelHeadRows() {
        return delHeadRows;
    }

    /**
     * 删除头部行数，空行不算
     *
     * @param delHeadRows
     * @return
     */
    public AnalysisParam setDelHeadRows(int delHeadRows) {
        this.delHeadRows = delHeadRows;
        return this;
    }

    public String getCharset() {
        return charset;
    }

    /**
     * 指定解析的文件编码，判断不准时，需要指定
     *
     * @param charset
     * @return
     */
    public AnalysisParam setCharset(String charset) {
        this.charset = charset;
        return this;
    }

    /**
     * 头部行记数
     *
     * @return
     */
    public int getHeadRowCountAndAdd() {
        return headRowCount++;
    }

    public String getExt() {
        return ext;
    }

    /**
     * 指定文件扩展号(解析类型)
     *
     * @param ext
     * @return
     */
    public AnalysisParam setExt(String ext) {
        this.ext = ext;
        return this;
    }

    public String getSplitRegex() {
        return splitRegex;
    }

    /**
     * txt文件分割正则
     *
     * @param splitRegex
     * @return
     */
    public AnalysisParam setSplitRegex(String splitRegex) {
        this.splitRegex = splitRegex;
        return this;
    }

    public int getSplitLimit() {
        return splitLimit;
    }

    /**
     * txt文件分割列数
     *
     * @param splitLimit -1为不分列
     * @return
     */
    public AnalysisParam setSplitLimit(int splitLimit) {
        this.splitLimit = splitLimit;
        return this;
    }

    /**
     * 需要重置的参数
     */
    public void reset() {
        headRowCount = 0;
    }

    public int getHeadRowCount() {
        return headRowCount;
    }
}
